package com.zxy.supplier_system.server.utils.tencent.position

// SearchPlace.kt
import com.fasterxml.jackson.annotation.JsonProperty
import org.springframework.http.ResponseEntity

// 响应数据类
data class SearchPlaceResponse(
    val status: Int,
    val message: String,
    val count: Int? = null,
    val data: List<PoiItem>,
){
    data class PoiItem(
        val id: String,
        val title: String,
        val address: String,
        val tel: String?,
        val category: String,
        val type: Int,
        val location: Location,
        @field:JsonProperty("ad_info") val adInfo: AdInfo,
    ){
        data class Location(
            val lat: Double,
            val lng: Double
        )

        data class AdInfo(
            val adcode: String,
            val province: String,
            val city: String,
            val district: String
        )
    }
}







// 扩展函数
fun TencentWebPositionClient.searchPlace(keyword:String,boundary:String,page_size:Int=10,page_index:Int=1): SearchPlaceResponse {

    // 构建参数映射
    val params = mutableMapOf(
        "keyword" to keyword,
        "boundary" to boundary,
        "page_size" to page_size.toString(),
        "page_index" to page_index.toString(),
        "key" to key
    )


    // 计算签名
    val result = calculateSignature(params, "/ws/place/v1/search")


    // 发送请求
    val response: ResponseEntity<String> = restTemplate.getForEntity(host+result.path, String::class.java)

    // 解析JSON响应
    return objectMapper.readValue(response.body, SearchPlaceResponse::class.java)
}